//
//  FreshFoodTopView.swift
//  SmartHousekeeper
//
//  Created by 刘森 on 2020/2/20.
//  Copyright © 2020 LS. All rights reserved.
//

import UIKit



class FreshFoodTopView: UIView {
    
    
    var searchBarView = FreshFoodSearchBarView()
    lazy var cityButton: UIButton = {
        let value = UIButton(textColor: UIColor.black, textFont: KFont(17))
        value.setTitle("株洲市", for: .normal)
        value.titleLabel?.adjustsFontSizeToFitWidth = true
        return value
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubviews([searchBarView,cityButton])
        
    }
    
    override func layoutSubviews() {
        searchBarView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(Adapter(20))
            make.height.equalTo(Adapter(40))
            make.right.equalToSuperview().offset(-Adapter(110))
        }
        cityButton.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(searchBarView.snp.right).offset(Adapter(12))
            make.right.equalToSuperview().offset(-Adapter(12))
            make.height.equalTo(Adapter(36))
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


class FreshFoodSearchBarView: UIView {
    
    let leftImageView = UIImageView(image: ImageName("suosou"))
    lazy var textField: UITextField = {
        let value = UITextField()
        value.attributedPlaceholder = NSAttributedString(string: "新鲜水果", attributes: [NSAttributedString.Key.font: KFont(16), NSAttributedString.Key.foregroundColor: KColorRGBA(185, 159, 128)])
        return value
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = KColorRGBA(248, 245, 242)
        self.layer.borderWidth = 0.5
        self.layer.borderColor = KColorRGBA(202, 204, 208).cgColor
        self.layer.cornerRadius = 20
        
        self.addSubviews([leftImageView, textField])

    }
    
    override func layoutSubviews() {
        leftImageView.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(Adapter(12))
            make.width.height.equalTo(18)
        }
        textField.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(leftImageView.snp.right).offset(Adapter(8))
            make.right.equalToSuperview()
            make.height.equalTo(Adapter(30))
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
